#include	<stdlib.h>
#include	<unistd.h>
#include	"get_next_line.h"

int		my_strlen(char *str)
{
  int		i;

  i = 0;
  while (str[i])
    i++;
  return (i);
}

int		count_size(char *s1, char *s2)
{
  int		res;

  res = 0;
  res = (my_strlen(s1) + my_strlen(s2));
  return (res);
}

char            *my_concat(char *str, char *str2)
{
  char          *str3;
  int           i;
  int           j;
  int           k;

  i = 0;
  j = 0;
  k = 0;
  if ((str3 = malloc((my_strlen(str) + my_strlen(str2))
                      * sizeof(str3))) == NULL)
    return (NULL);
  while (str[i])
    str3[k++] = str[i++];
  while (str2[j])
    str3[k++] = str2[j++];
  str3[k] = '\0';
  return (str3);
}
char		*get_next_line(const int fd)
{
  char		buffer[SIZE_MAX];
  int		i;
  static char	*ret;
  static int	j = 0;
  char		*tmp;

  i = 0;
  ret = malloc(sizeof(*ret) * count_size(ret, buffer));
  if ((read(fd, buffer, SIZE_MAX)) == -1)
    return (NULL);
  printf("%s\n", buffer);
  while (buffer[j] != '\n' && j <= SIZE_MAX)
    {
      if ((tmp = malloc(sizeof(*tmp) * SIZE_MAX)) == NULL)
	return (NULL);
      ret[j] = buffer[i++];
      printf("%c\n", buffer[i]);
      j++;
    }
  ret[j] = '\0';
  tmp = my_strdup(ret);
  return (ret);
}
